sgdk: vdp_tile.h File Reference

sgdk

- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

Classes | Defines | Functions
vdp_tile.h File Reference

VDP General Tile / Tilemap operations. More...

Go to the source code of this file.

## Classes

struct | TileSet
struct | Map

## Defines

#define | TILE_ATTR_PRIORITY_MASK 0x8000
#define | TILE_ATTR_PALETTE_MASK 0x6000
#define | TILE_ATTR_VFLIP_MASK 0x1000
#define | TILE_ATTR_HFLIP_MASK 0x0800
#define | TILE_ATTR_MASK (TILE_ATTR_PRIORITY_MASK | TILE_ATTR_PALETTE_MASK | TILE_ATTR_VFLIP_MASK | TILE_ATTR_HFLIP_MASK)
#define | TILE_ATTR(pal, prio, flipV, flipH) (((flipH) << 11) + ((flipV) << 12) + ((pal) << 13) + ((prio) << 15))
#define | TILE_ATTR_FULL(pal, prio, flipV, flipH, index) (((flipH) << 11) + ((flipV) << 12) + ((pal) << 13) + ((prio) << 15) + (index))

## Functions

void | VDP_loadTileData (const u32 *data, u16 index, u16 num, u8 use_dma)
| Load tile data (pattern) in VRAM.
u16 | VDP_loadTileSet (const TileSet *tileset, u16 index, u8 use_dma)
| Load tile data (pattern) in VRAM.
void | VDP_loadFontData (const u32 *font, u16 length, u8 use_dma)
| Load font tile data in VRAM. Note that you should prefer the VDP_loadBMPFont(..) method to this one (easier to use).
u16 | VDP_loadFont (const TileSet *font, u8 use_dma)
| Load font from the specified TileSet structure.
void | VDP_loadBMPTileData (const u32 *data, u16 index, u16 w, u16 h, u16 bmp_w)
| Load 4bpp bitmap tile data in VRAM.
void | VDP_loadBMPTileDataEx (const u32 *data, u16 index, u16 x, u16 y, u16 w, u16 h, u16 bmp_w)
| Load 4bpp bitmap tile data in VRAM.
void | VDP_fillTileData (u8 value, u16 index, u16 num, u8 use_dma)
| Fill tile data in VRAM.
void | VDP_setTileMap (u16 plan, u16 tile, u16 ind)
| Set tilemap data at single position.
void | VDP_setTileMapXY (u16 plan, u16 tile, u16 x, u16 y)
| Set tilemap data at single position.
void | VDP_fillTileMapRectByIndex (u16 plan, u16 tile, u16 ind, u16 num)
void | VDP_fillTileMap (u16 plan, u16 tile, u16 ind, u16 num)
| Fill tilemap data.
void | VDP_fillTileMapRect (u16 plan, u16 tile, u16 x, u16 y, u16 w, u16 h)
| Fill tilemap data at specified region.
void | VDP_clearTileMapRectByIndex (u16 plan, u16 ind, u16 num, u8 use_dma)
void | VDP_clearTileMap (u16 plan, u16 ind, u16 num, u8 use_dma)
| Clear tilemap data.
void | VDP_clearTileMapRect (u16 plan, u16 x, u16 y, u16 w, u16 h)
| Clear tilemap data at specified region.
void | VDP_fillTileMapRectIncByIndex (u16 plan, u16 basetile, u16 ind, u16 num)
void | VDP_fillTileMapInc (u16 plan, u16 basetile, u16 ind, u16 num)
| Fill tilemap data with index auto increment.
void | VDP_fillTileMapRectInc (u16 plan, u16 basetile, u16 x, u16 y, u16 w, u16 h)
| Fill tilemap data with index auto increment at specified region.
void | VDP_setTileMapRectByIndex (u16 plan, const u16 *data, u16 ind, u16 num, u8 use_dma)
void | VDP_setTileMapData (u16 plan, const u16 *data, u16 ind, u16 num, u8 use_dma)
| Load tilemap data at specified index.
void | VDP_setTileMapDataRect (u16 plan, const u16 *data, u16 x, u16 y, u16 w, u16 h)
| Load tilemap data at specified region.
void | VDP_setTileMapRectExByIndex (u16 plan, const u16 *data, u16 baseindex, u16 baseflags, u16 ind, u16 num)
| Use VDP_setTileMapDataEx() instead.
void | VDP_setTileMapDataEx (u16 plan, const u16 *data, u16 basetile, u16 ind, u16 num)
| Load tilemap data at specified index (extended version).
void | VDP_setTileMapRectEx (u16 plan, const u16 *data, u16 baseindex, u16 baseflags, u16 x, u16 y, u16 w, u16 h)
void | VDP_setTileMapDataRectEx (u16 plan, const u16 *data, u16 basetile, u16 x, u16 y, u16 w, u16 h, u16 wm)
| Load tilemap data at specified region (extended version).
u16 | VDP_setMap (u16 plan, const Map *map, u16 basetile, u16 x, u16 y)
| Load Map at specified position.
u16 | VDP_setMapEx (u16 plan, const Map *map, u16 basetile, u16 x, u16 y, u16 xm, u16 ym, u16 wm, u16 hm)
| Load Map region at specified position.

## Detailed Description

VDP General Tile / Tilemap operations.

Author:
  Stephane Dallongeville

Date:
  08/2011

This unit provides methods to manipulate VDP tiles and tilemap :

- upload tiles to VDP memory
- upload tiles to VDP memory from bitmap data
- clear / fill / set tile map data

## Define Documentation

#define TILE_ATTR | ( |  | pal,
|  |  | prio,
|  |  | flipV,
|  |  | flipH
| ) |  | (((flipH) << 11) + ((flipV) << 12) + ((pal) << 13) + ((prio) << 15))

Encode tile attributes for tilemap data.

Parameters:

  pal | Palette index
  prio | Tile priority
  flipV | Vertical flip
  flipH | Horizontal flip

#define TILE_ATTR_FULL | ( |  | pal,
|  |  | prio,
|  |  | flipV,
|  |  | flipH,
|  |  | index
| ) |  | (((flipH) << 11) + ((flipV) << 12) + ((pal) << 13) + ((prio) << 15) + (index))

Encode tile attributes for tilemap data.

Parameters:

  pal | Palette index
  prio | Tile priority
  flipV | Vertical flip
  flipH | Horizontal flip
  index | Tile index

#define TILE_ATTR_HFLIP_MASK 0x0800

Mask for the tile H flip attribute in tilemap data.

#define TILE_ATTR_MASK (TILE_ATTR_PRIORITY_MASK | TILE_ATTR_PALETTE_MASK | TILE_ATTR_VFLIP_MASK | TILE_ATTR_HFLIP_MASK)

Mask for the tile attributes (priority, palette and flip) in tilemap data.

#define TILE_ATTR_PALETTE_MASK 0x6000

Mask for the tile palette attribute in tilemap data.

#define TILE_ATTR_PRIORITY_MASK 0x8000

Mask for the tile priority attribute in tilemap data.

#define TILE_ATTR_VFLIP_MASK 0x1000

Mask for the tile V flip attribute in tilemap data.

## Function Documentation

void VDP_clearTileMap | ( | u16 | plan,
|  | u16 | ind,
|  | u16 | num,
|  | u8 | use_dma
| ) |  |

Clear tilemap data.

Parameters:

  plan

  Plan where we want to clear tilemap region.
  Accepted values are:
  - VDP_PLAN_A
  - VDP_PLAN_B

  ind | Tile index where to start fill.
  num | Number of tile to fill.
  use_dma | Use DMA transfert (faster but can lock Z80 execution).

See also:
  VDP_fillTileMap() (faster method)
  VDP_fillTileMapRectInc()
  VDP_clearTileMapRect()

void VDP_clearTileMapRect | ( | u16 | plan,
|  | u16 | x,
|  | u16 | y,
|  | u16 | w,
|  | u16 | h
| ) |  |

Clear tilemap data at specified region.

Parameters:

  plan

  Plan where we want to clear tilemap region.
  Accepted values are:
  - VDP_PLAN_A
  - VDP_PLAN_B

  x | Region X start position (in tile).
  y | Region Y start position (in tile).
  w | Region Width (in tile).
  h | Region Heigh (in tile).

See also:
  VDP_clearTileMap() (faster method)

void VDP_clearTileMapRectByIndex | ( | u16 | plan,
|  | u16 | ind,
|  | u16 | num,
|  | u8 | use_dma
| ) |  |

Deprecated:
  Use VDP_clearTileMap() instead

void VDP_fillTileData | ( | u8 | value,
|  | u16 | index,
|  | u16 | num,
|  | u8 | use_dma
| ) |  |

Fill tile data in VRAM.

Parameters:

  value | Value (byte) used to fill VRAM tile data.
  index | Tile index where start tile data fill (use TILE_USERINDEX as base user index).
  num | Number of tile to fill.
  use_dma | Use DMA transfert (faster but can lock Z80 execution).

This function is generally used to clear tile data in VRAM.

void VDP_fillTileMap | ( | u16 | plan,
|  | u16 | tile,
|  | u16 | ind,
|  | u16 | num
| ) |  |

Fill tilemap data.

Parameters:

  plan

  Plan where we want to fill tilemap data.
  Accepted values are:
  - VDP_PLAN_A
  - VDP_PLAN_B

  tile | tile attributes data (see TILE_ATTR_FULL() and TILE_ATTR() macros).
  ind | tile index where to start fill.
  num | Number of tile to fill.

See also:
  VDP_fillTileMapRect()
  VDP_fillTileMapRectInc()

void VDP_fillTileMapInc | ( | u16 | plan,
|  | u16 | basetile,
|  | u16 | ind,
|  | u16 | num
| ) |  |

Fill tilemap data with index auto increment.

Parameters:

  plan

  Plan where we want to fill tilemap region.
  Accepted values are:
  - VDP_PLAN_A
  - VDP_PLAN_B

  basetile | Base tile attributes data (see TILE_ATTR_FULL() and TILE_ATTR() macros).
  ind | tile index where to start fill.
  num | Number of tile to fill.

Set the specified tilemap with specified tile attributes values.
The function auto increments tile index in tile attribute :
tilemap at index : basetile, basetile+1, basetile+2, basetile+3, ...
...
So this function is pratical to display image.

See also:
  also VDP_fillTileMap()
  also VDP_fillTileMapRectInc()

void VDP_fillTileMapRect | ( | u16 | plan,
|  | u16 | tile,
|  | u16 | x,
|  | u16 | y,
|  | u16 | w,
|  | u16 | h
| ) |  |

Fill tilemap data at specified region.

Parameters:

  plan

  Plan where we want to fill tilemap region.
  Accepted values are:
  - VDP_PLAN_A
  - VDP_PLAN_B

  tile | tile attributes data (see TILE_ATTR_FULL() and TILE_ATTR() macros).
  x | Region X start position (in tile).
  y | Region Y start position (in tile).
  w | Region Width (in tile).
  h | Region Heigh (in tile).

Fill the specified tilemap region with specified tile attributes values.

See also:
  VDP_fillTileMap() (faster method)
  VDP_fillTileMapRectInc()

void VDP_fillTileMapRectByIndex | ( | u16 | plan,
|  | u16 | tile,
|  | u16 | ind,
|  | u16 | num
| ) |  |

Deprecated:
  Use VDP_fillTileMap() instead

void VDP_fillTileMapRectInc | ( | u16 | plan,
|  | u16 | basetile,
|  | u16 | x,
|  | u16 | y,
|  | u16 | w,
|  | u16 | h
| ) |  |

Fill tilemap data with index auto increment at specified region.

Parameters:

  plan

  Plan where we want to fill tilemap region.
  Accepted values are:
  - VDP_PLAN_A
  - VDP_PLAN_B

  basetile | Base tile attributes data (see TILE_ATTR_FULL() and TILE_ATTR() macros).
  x | Region X start position (in tile).
  y | Region Y start position (in tile).
  w | Region Width (in tile).
  h | Region Heigh (in tile).

Set the specified tilemap region with specified tile attributes values.
The function auto increments tile index in tile attribute :
tilemap line 0 : basetile, basetile+1, basetile+2, basetile+3, ...
tilemap line 1 : basetile+w, basetile+w+1, basetile+w+2, ...
...
So this function is pratical to display image.

See also:
  also VDP_fillTileMapInc() (faster method)
  also VDP_fillTileMapRect()

void VDP_fillTileMapRectIncByIndex | ( | u16 | plan,
|  | u16 | basetile,
|  | u16 | ind,
|  | u16 | num
| ) |  |

Deprecated:
  Use VDP_fillTileMapInc() instead.

void VDP_loadBMPTileData | ( | const u32 * | data,
|  | u16 | index,
|  | u16 | w,
|  | u16 | h,
|  | u16 | bmp_w
| ) |  |

Load 4bpp bitmap tile data in VRAM.

Parameters:

  data | Pointer to 4bpp bitmap tile data.
  index | Tile index where start tile data load (use TILE_USERINDEX as base user index).
  w | Width of bitmap region to load (in tile).
  h | Heigh of bitmap region to load (in tile).
  bmp_w | Width of bitmap (in tile), it can differ from 'w' parameter.

This function does "on the fly" 4bpp bitmap conversion to tile data and transfert them to VRAM.
It's very helpful when you use bitmap images but the conversion eats sometime so you should use it only for static screen only.
For "in-game" condition you should use VDP_loadTileData() method with converted tile data.
See also VDP_loadBMPTileDataEx().

void VDP_loadBMPTileDataEx | ( | const u32 * | data,
|  | u16 | index,
|  | u16 | x,
|  | u16 | y,
|  | u16 | w,
|  | u16 | h,
|  | u16 | bmp_w
| ) |  |

Load 4bpp bitmap tile data in VRAM.

Parameters:

  data | Pointer to 4bpp bitmap tile data.
  index | Tile index where start tile data load (use TILE_USERINDEX as base user index).
  x | X start position of bitmap region to load (in tile).
  y | Y start position of bitmap region to load (in tile).
  w | Width of bitmap region to load (in tile).
  h | Heigh of bitmap region to load (in tile).
  bmp_w | Width of bitmap (in tile), it can differ from 'w' parameter.

This function does "on the fly" 4bpp bitmap conversion to tile data and transfert them to VRAM.
It's very helpful when you use bitmap images but the conversion eats sometime so you should use it only for static screen only.
For "in-game" condition you should use VDP_loadTileData() method with converted tile data. See also VDP_loadBMPTileData()

u16 VDP_loadFont | ( | const TileSet * | font,
|  | u8 | use_dma
| ) |  |

Load font from the specified TileSet structure.

Parameters:

  font | TileSet containing the font. The TileSet is unpacked "on-the-fly" if needed (require some memory)
  use_dma | Use DMA transfert (faster but can lock Z80 execution).

Returns:
  FALSE if there is not enough memory to unpack the specified font (only if compression was enabled).

This fonction permits to replace system font by user font.
The font tile data are loaded to TILE_FONTINDEX and can contains FONT_LEN characters at max.
Each character should fit in one tile (8x8 pixels bloc).
See also VDP_loadFontData(..)

void VDP_loadFontData | ( | const u32 * | font,
|  | u16 | length,
|  | u8 | use_dma
| ) |  |

Load font tile data in VRAM.
Note that you should prefer the VDP_loadBMPFont(..) method to this one (easier to use).

Parameters:

  font | Pointer to font tile data.
  length | Number of characters of the font (max = FONT_LEN).
  use_dma | Use DMA transfert (faster but can lock Z80 execution).

This fonction permits to replace system font by user font.
The font tile data are loaded to TILE_FONTINDEX and can contains FONT_LEN characters at max.
Each character should fit in one tile (8x8 pixels bloc).
See also VDP_loadFont(..) and VDP_loadTileData(..)

void VDP_loadTileData | ( | const u32 * | data,
|  | u16 | index,
|  | u16 | num,
|  | u8 | use_dma
| ) |  |

Load tile data (pattern) in VRAM.

Parameters:

  data | Pointer to tile data.
  index | Tile index where start tile data load (use TILE_USERINDEX as base user index).
  num | Number of tile to load.
  use_dma | Use DMA transfert (faster but can lock Z80 execution).

Transfert rate:
~90 bytes per scanline in software (during blanking)
~190 bytes per scanline in hardware (during blanking)

u16 VDP_loadTileSet | ( | const TileSet * | tileset,
|  | u16 | index,
|  | u8 | use_dma
| ) |  |

Load tile data (pattern) in VRAM.

Parameters:

  tileset | Pointer to TileSet structure. The TileSet is unpacked "on-the-fly" if needed (require some memory)
  index | Tile index where start tile data load (use TILE_USERINDEX as base user index).
  use_dma | Use DMA transfert (faster but can lock Z80 execution).

Returns:
  FALSE if there is not enough memory to unpack the specified TileSet (only if compression was enabled).

Transfert rate:
~90 bytes per scanline in software (during blanking)
~190 bytes per scanline in hardware (during blanking)

u16 VDP_setMap | ( | u16 | plan,
|  | const Map * | map,
|  | u16 | basetile,
|  | u16 | x,
|  | u16 | y
| ) |  |

Load Map at specified position.

Parameters:

  plan

  Plan where we want to load Map.
  Accepted values are:
  - VDP_PLAN_A
  - VDP_PLAN_B

  map | Map to load.
  basetile | Base index and flags for tile attributes (see TILE_ATTR_FULL() macro).
  x | Region X start position (in tile).
  y | Region Y start position (in tile).

Load the specified Map at specified plan position.

See also:
  VDP_setTileMapData()
  VDP_setTileMapDataEx()

u16 VDP_setMapEx | ( | u16 | plan,
|  | const Map * | map,
|  | u16 | basetile,
|  | u16 | x,
|  | u16 | y,
|  | u16 | xm,
|  | u16 | ym,
|  | u16 | wm,
|  | u16 | hm
| ) |  |

Load Map region at specified position.

Parameters:

  plan

  Plan where we want to load Map.
  Accepted values are:
  - VDP_PLAN_A
  - VDP_PLAN_B

  map | Map to load.
  basetile | Base index and flags for tile attributes (see TILE_ATTR_FULL() macro).
  x | Plan X destination position (in tile).
  y | Plan Y destination position (in tile).
  xm | Map region X start position (in tile).
  ym | Map region Y start position (in tile).
  wm | Map region Width (in tile).
  hm | Map region Heigh (in tile).

Load the specified Map region at specified plan position.

See also:
  VDP_setTileMapDataRect()
  VDP_setTileMapDataRectEx()

void VDP_setTileMap | ( | u16 | plan,
|  | u16 | tile,
|  | u16 | ind
| ) |  |

Set tilemap data at single position.

Parameters:

  plan

  Plan where we want to set tilemap data.
  Accepted values are:
  - VDP_PLAN_A
  - VDP_PLAN_B

  tile | tile attributes data (see TILE_ATTR_FULL() and TILE_ATTR() macros).
  ind | position in tilemap.

void VDP_setTileMapData | ( | u16 | plan,
|  | const u16 * | data,
|  | u16 | ind,
|  | u16 | num,
|  | u8 | use_dma
| ) |  |

Load tilemap data at specified index.

Parameters:

  plan

  Plan where we want to load tilemap data.
  Accepted values are:
  - VDP_PLAN_A
  - VDP_PLAN_B

  data | Tile attributes data pointer (see TILE_ATTR_FULL() and TILE_ATTR() macros).
  ind | Tile index where to start to set tilemap.
  num | Number of tile to set.
  use_dma | Use DMA transfert (faster but can lock Z80 execution).

Set the specified tilemap with specified tile attributes values.
Transfert rate:
~90 bytes per scanline in software (during blanking)
~190 bytes per scanline in hardware (during blanking)

See also:
  VDP_setTileMapDataEx().
  VDP_setTileMapDataRect().

void VDP_setTileMapDataEx | ( | u16 | plan,
|  | const u16 * | data,
|  | u16 | basetile,
|  | u16 | ind,
|  | u16 | num
| ) |  |

Load tilemap data at specified index (extended version).

Parameters:

  plan

  Plan where we want to load tilemap data.
  Accepted values are:
  - VDP_PLAN_A
  - VDP_PLAN_B

  data | tile attributes data pointer (see TILE_ATTR_FULL() and TILE_ATTR() macros).
  basetile | Base tile index and flags for tile attributes (see TILE_ATTR_FULL() macro).
  ind | Tile index where to start to set tilemap.
  num | Number of tile to set.

Set the specified tilemap with specified tile attributes values.

See also:
  VDP_setTileMapData()
  VDP_setTileMapDataRectEx()

void VDP_setTileMapDataRect | ( | u16 | plan,
|  | const u16 * | data,
|  | u16 | x,
|  | u16 | y,
|  | u16 | w,
|  | u16 | h
| ) |  |

Load tilemap data at specified region.

Parameters:

  plan

  Plan where we want to load tilemap data.
  Accepted values are:
  - VDP_PLAN_A
  - VDP_PLAN_B

  data | tile attributes data pointer (see TILE_ATTR_FULL() and TILE_ATTR() macros).
  x | Region X start position (in tile).
  y | Region Y start position (in tile).
  w | Region Width (in tile).
  h | Region Heigh (in tile).

Set the specified tilemap region with specified tile attributes values.

See also:
  VDP_setTileMapDataRectEx().
  VDP_setTileMapData().

void VDP_setTileMapDataRectEx | ( | u16 | plan,
|  | const u16 * | data,
|  | u16 | basetile,
|  | u16 | x,
|  | u16 | y,
|  | u16 | w,
|  | u16 | h,
|  | u16 | wm
| ) |  |

Load tilemap data at specified region (extended version).

Parameters:

  plan

  Plan where we want to load tilemap data.
  Accepted values are:
  - VDP_PLAN_A
  - VDP_PLAN_B

  data | tile attributes data pointer (see TILE_ATTR_FULL() macro).
  basetile | Base index and flags for tile attributes (see TILE_ATTR_FULL() macro).
  x | Region X start position (in tile).
  y | Region Y start position (in tile).
  w | Region Width (in tile).
  h | Region Heigh (in tile).
  wm | Source tilemap data width (in tile).

Set the specified tilemap region with specified tile attributes values.

See also:
  VDP_setTileMapDataRect()
  VDP_setTileMapDataEx()

void VDP_setTileMapRectByIndex | ( | u16 | plan,
|  | const u16 * | data,
|  | u16 | ind,
|  | u16 | num,
|  | u8 | use_dma
| ) |  |

Deprecated:
  Use VDP_setTileMapData() instead.

void VDP_setTileMapRectEx | ( | u16 | plan,
|  | const u16 * | data,
|  | u16 | baseindex,
|  | u16 | baseflags,
|  | u16 | x,
|  | u16 | y,
|  | u16 | w,
|  | u16 | h
| ) |  |

Deprecated:
  Use VDP_setTileMapDataRectEx() instead.

void VDP_setTileMapXY | ( | u16 | plan,
|  | u16 | tile,
|  | u16 | x,
|  | u16 | y
| ) |  |

Set tilemap data at single position.

Parameters:

  plan

  Plan where we want to set tilemap data.
  Accepted values are:
  - VDP_PLAN_A
  - VDP_PLAN_B

  tile | tile attributes data (see TILE_ATTR_FULL() and TILE_ATTR() macros).
  x | X position (in tile).
  y | y position (in tile).

All Classes Files Functions Variables Typedefs Enumerations Defines